package democmp;

import java.util.Arrays;

public class text {
    public static void main(String[] args){
        Student student1=new Student("bit", 10);
        Student student2=new Student("hello",8);
        Student student3=new Student("nm",12);
        Student[] students=new Student[3];
        students[0]=student1;
        students[1]=student2;
        students[2]=student3;
        NameComparator nameComparator=new NameComparator();
        System.out.println("排序前："+Arrays.toString(students));
        Arrays.sort(students,nameComparator);
        System.out.println("排序后："+Arrays.toString(students));
    }
    public static void main1(String[] args){
        Student student1=new Student("bit",10);
        Student student2=new Student("hello",5);
        //1.接口comparable中compareTo方法的使用；
        if(student1.compareTo(student2)>0){
            System.out.println("student1>student2");
        }
        System.out.println("===================");
        //2.比较器comparator的使用；
    NameComparator nameComparator=new NameComparator();
    int ret= nameComparator.compare(student1,student2);
    if(ret>0){
        System.out.println("student1>student2");
    }else{
        System.out.println("student2>student1");
    }
    System.out.println("========================");
    AgeComparator ageComparator=new AgeComparator();
    int ret1 = ageComparator.compare(student1,student2);
    if(ret1>0){
        System.out.println("student1>student2");
    }else{
        System.out.println("student2<student1");
    }

    }
}
